import path from 'path';
import { defineConfig, type UserConfig } from 'rspress/config';
import { DotenvRunPlugin } from '@dotenv-run/rspack';

const toolsConfig = defineConfig({
  // 文档根目录
  root: path.join(__dirname, 'docs'),
  route: {
    exclude: ['components'],
  },
  builderConfig: {
    server: {
      port: 9890,
    },
    tools: {
      rspack(_:{}, { appendPlugins }) {
        appendPlugins(
          new DotenvRunPlugin({
            verbose: true,
          }),
        );
      },
    },
  },
});
//// 
const themeConfig = defineConfig({
  title: 'Rspress',
  description: 'Rspack-based Static Site Generator',
  icon: '/rspress-icon.png',
  logo: {
    light: '/rspress-light-logo.png',
    dark: '/rspress-dark-logo.png',
  },
  themeConfig: {
    socialLinks: [
      {
        icon: 'github',
        mode: 'link',
        content: 'https://github.com/web-infra-dev/rspress',
      },
    ],
  },
});

export default mergeConfig(toolsConfig, themeConfig);

function mergeConfig(userConfig: UserConfig, themeConfig: UserConfig) {
  return Object.assign(themeConfig, userConfig);
}
